import time
from selenium import webdriver
from selenium.webdriver.common.by import By
import os
from selenium.webdriver.support.select import Select

# select 下拉框的操作
class TestCase:

    def __init__(self) -> None:
        self.driver=webdriver.Chrome()
        path=os.path.dirname( os.path.abspath(__file__) )
        file_path='file:///'+path+'/16 select.html'
        self.driver.get(file_path)
        time.sleep(3)

    def test_select(self):
        province=self.driver.find_element(By.ID,'province')
        #注意看上面的导入Select类,这里是实例化Select类，需要传入一个WebElement对象
        select=Select(province)
        select.select_by_index(1)#选择第二个选项，索引从0开始
        time.sleep(3)
        select.select_by_visible_text('四川')
        time.sleep(3)

if __name__ == '__main__':
    case=TestCase()        
    case.test_select()